<html>
<head>
<style type="text/css">
body {
  font-family: arial, sans-serif;
  font-size: 13px;
  width: 230px;
}
.menu, .menu-disable {
  border: 1px solid #bec9ce;
  margin-top: 5px;
  line-height: 22px;
  text-indent: 1em;
  width: 220px;
  display: none;
}
.menu {
  color: #3d5d6a;
  cursor: pointer;
}
.menu-disable {
  color: #bec9ce;
  cursor: default;
}
.menu:hover {
  background-color: #3d5d6a;
  color: #ffffff;
}

</style>
<script>
function init() {
  var thunder = document.getElementById('btnThunder');
  var flashget = document.getElementById('btnFlashget');
  var tip = document.getElementById('tip');
  thunder.innerText = chrome.i18n.getMessage('downloadAllByThunder');
  flashget.innerText = chrome.i18n.getMessage('downloadAllByFlashget');

  tip.innerText = chrome.i18n.getMessage('tipUnable');

  if (eval(localStorage.thunder)) {
    thunder.className = 'menu';
    thunder.style.display = 'block';
  }
  if (eval(localStorage.flashget))  {
    flashget.className = 'menu';
    flashget.style.display = 'block';
  }




  document.getElementById('tip').style.display = 'none';
//  chrome.tabs.getSelected(null, function(tab) {
//    chrome.tabs.sendRequest(tab.id, {msg: 'content_script_is_load'},
//        function(response) {
//          if (response) {
//            document.getElementById('btnThunder').style.display = 'block';
//            document.getElementById('btnFlashget').style.display = 'block';
//            document.getElementById('tip').style.display = 'none';
//          }
//        });
//    });
}
function downloadAllByThunder() {
  chrome.tabs.executeScript(null, {code : 'sendDownloadCommandToBg("ByThunder");'});
}
function downloadAllByFlashget() {
  chrome.tabs.executeScript(null, {code : 'sendDownloadCommandToBg("ByFlashget");'});
}


chrome.extension.onRequest.addListener(function (request, sender, response){
  if (request && request.msg == 'noLink') {
    document.getElementById('btnThunder').style.display = 'none';
    document.getElementById('btnFlashget').style.display = 'none';
    document.getElementById('tip').innerText = chrome.i18n.getMessage('tipNolink');
    document.getElementById('tip').style.display = 'block';
  }
});


</script>
</head>
<body onload="init()">
  <div id="item">
    <div class="menu-disable" onclick="downloadAllByFlashget()" id="btnFlashget"></div>
    <div class="menu-disable" onclick="downloadAllByThunder()" id="btnThunder"></div>
    <div id="tip"></div>
  </div>
</body>
</html>
